import sys
sys.path.append("../")
from services.DataService import *
from controller.BaseController import *
import hashlib

class UserController(BaseController):
    def __init__(self,args):
        super(UserController,self).__init__()
        self.args = args
        self.services = DataService()

    def run(self):
        username = self.args["username"]
        url = "/query/users/select|*/where|username=@" + self.args["username"] + "@|password=@" + self.args["password"] + "@"
        rs = self.services.getData(url,{})
        user = {}
        if len(rs) > 0:
            user["token"] = hashlib.md5(username.encode(encoding='utf-8')).hexdigest()
            user["userid"] = rs[0]["id"]
        else:
            pass
        return self.rs.setOk("获取成功",user)